package com.jn.factory.simplefactory.pizzastore.order;

import com.jn.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.jn.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.jn.factory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author 江南大学1033190417
 * @date 2022/4/10 18:55
 */
public class OrderPizza {
//    public OrderPizza() {
//        Pizza pizza = null;
//        String orderType;
//        do {
//            orderType = getType();
//            if (orderType.equals("greek")) {
//                pizza = new GreekPizza();
//                pizza.setName(" 希腊披萨 ");
//            } else if (orderType.equals("cheese")) {
//                pizza = new CheesePizza();
//                pizza.setName(" 奶酪披萨 ");
//            } else {
//                break;
//            }
//            //输出 pizza 制作过程
//            pizza.prepare();
//            pizza.bake();
//            pizza.cut();
//            pizza.box();
//        } while (true);
//    }

    //构造器
    public OrderPizza(SimpleFactory simpleFactory){
        setSimpleFactory(simpleFactory);
    }
    //定义一个简单工厂对象

    SimpleFactory simpleFactory;
    Pizza pizza=null;
    public void setSimpleFactory(SimpleFactory simpleFactory){
        String orderType="";
        this.simpleFactory=simpleFactory;
        do {
            orderType=getType();
            pizza=this.simpleFactory.createPizza(orderType);
            if (pizza!=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
            }
        }while (true);
    }

    private String getType(){
        try {
            BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("输入Pizza：");
            String str=strin.readLine();
            return str;
        }catch (Exception e){
            return "";
        }
    }
}
